//
//  LHLLayout.m
//  15-HomeWork
//
//  Created by 李昊林 on 16/8/3.
//  Copyright © 2016年 李昊林. All rights reserved.
//
#import "LHLLayout.h"

@interface LHLLayout ()
@property (nonatomic, strong) NSMutableArray *array;
@property (nonatomic, assign) CGFloat height;
@property (nonatomic, assign) CGFloat WIDTH;
@end
@implementation LHLLayout

//- (instancetype)initWithCoder:(NSCoder *)aDecoder {
//
//}






- (instancetype)init {
    if (self = [super init]) {
        _array = [NSMutableArray array];
        _height = 44;
    }
    return self;
}
- (void)prepareLayout {
    [super prepareLayout];
    _WIDTH = 0;
    for (NSInteger i = 0; i < [self.collectionView numberOfItemsInSection:0]; i++) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
        UICollectionViewLayoutAttributes *att = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
        CGFloat width = [self.delegate collectionView:self.collectionView layout:self widthForItemAtIndexPath:indexPath height:_height];

            att.frame = CGRectMake(_WIDTH, 0, width, _height);
            [_array addObject:att];
      
        _WIDTH = _WIDTH + width + 20;
    }

}
- (nullable NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
    return _array;
}
- (CGFloat)att_width {
    return 44;
}
- (CGSize)collectionViewContentSize {
    return CGSizeMake(_WIDTH, 44);
}
@end
